﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows;
using System.Windows.Threading;
using System.Security;
using System.Threading;

namespace 测试窗体
{
    public class ScreenKeyboard
{
    private const uint SWP_NOSIZE = 0x0001;
    private const uint SWP_NOMOVE = 0x0002;
    private const uint SWP_NOZORDER = 0x0004;
     private const uint SWP_NOREDRAW = 0x0008;
    private const uint SWP_NOACTIVATE = 0x0010;
    private const uint SWP_FRAMECHANGED = 0x0020;
    private const uint SWP_SHOWWINDOW = 0x0040;
    private const uint SWP_HIDEWINDOW = 0x0080;
    private const uint SWP_NOCOPYBITS = 0x0100;
    private const uint SWP_NOOWNERZORDER = 0x0200;
    private const uint SWP_NOSENDCHANGING = 0x0400;
    
    [DllImport("user32.dll")]
    static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
                                    int Y, int cx, int cy, uint uFlags);
    [DllImport("User32.dll", EntryPoint = "FindWindow")]
    private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    [DllImport("User32.dll", EntryPoint = "FindWindowEx")]
    private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);  

    [DllImport("user32.dll")]
    static extern bool SetForegroundWindow(IntPtr hWnd);
    public static void ShowScreenKeyboard()
    {
        if (System.IO.File.Exists(Environment.SystemDirectory + "\\osk.exe"))
        {
            Process process = new Process();
            process.StartInfo.UseShellExecute = true;
            //process.StartInfo.RedirectStandardOutput = true;
            //process.StartInfo.RedirectStandardError = true;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.FileName = "osk.exe";
            //process.StartInfo.Verb = "runas";
            process.StartInfo.Arguments = "";
            process.Start(); 
            //process.WaitForInputIdle();
            //process.WaitForExit();
            //Thread.Sleep(1000);
            //IntPtr osk = FindWindow(null,"屏幕键盘");
            //IntPtr mw = FindWindow(null, "测试窗体");
            
            //System.Windows.Interop.WindowInteropHelper winHelper = new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow);
            //IntPtr mainWindowHandle = winHelper.Handle;
            //SetWindowPos(osk,
            //mw,
            //0, 
            //0, 
            //800, 
            //400,
            //SWP_SHOWWINDOW | SWP_NOZORDER);

          
            //SetForegroundWindow(osk);
          }

     }
}
}
